<?php

namespace App\Services\Code;

use App\Models\Sms;
use SmsService;


class CodeService
{

    //发送帐号
    protected $mobile;

    public function send($user)
    {
        $sms = Sms::find(1);
        $template = $sms->template;
        SmsService::mobile($user->mobile, [
            "template" => $template,
            "data" => [
                'code' => $this->code(),
                'product' => config('system.sms.product'),
            ],
        ]);
    }


    protected function code()
    {
        $code = mt_rand(1000, 9999);
        cache([$this->mobile => $code], now()->addMinutes(10));
        return $code;
    }


    public function check(string $account, string $code)
    {
        return cache($account) == $code;
    }


}
